package com.sudo.service.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.sudo.common.utils.PagedGridResult;
import com.sudo.dao.admin.entity.SysJobLog;
import com.sudo.dao.admin.mapper.SysJobLogMapper;
import com.sudo.dao.admin.model.bo.SysJobLogBO;
import com.sudo.service.admin.service.AdminBaseService;
import com.sudo.service.admin.service.SysJobLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysJobLogServiceImpl extends AdminBaseService implements SysJobLogService {
    @Resource
    private SysJobLogMapper sysJobLogMapper;

    @Override
    public PagedGridResult querySysJobLogByPage(SysJobLogBO sysJobLogBO) {
        PageHelper.startPage(sysJobLogBO.getPage(), sysJobLogBO.getPageSize());
        Example example = new Example(SysJobLog.class);
        example.excludeProperties("jobNoteDesc");
        example.orderBy("id").desc();
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("jobId", sysJobLogBO.getJobId());
        if (StringUtils.isNotBlank(sysJobLogBO.getJobResult())) {
            criteria.andEqualTo("jobResult", sysJobLogBO.getJobResult());
        }
        if (StringUtils.isNotBlank(sysJobLogBO.getJobAction())) {
            criteria.andEqualTo("jobAction", sysJobLogBO.getJobAction());
        }
        List<SysJobLog> sysJobLogList = sysJobLogMapper.selectByExample(example);
        return setterPagedGrid(sysJobLogList, sysJobLogBO.getPage());
    }

    @Override
    public SysJobLog getSysJobLog(Integer id) {
        return sysJobLogMapper.selectByPrimaryKey(id);
    }
}
